var docTypeStore=new Ext.data.JsonStore(
	{data:[{name:'供应商订单',value:'1'},
	{name:'客户订单',value:'2'}],
	fields:['name','value']
});

var docStateStore=new Ext.data.JsonStore({
	data:[{name:'未处理',value:'0'},
	{name:'订购成功',value:'1'},
	{name:'订购失败',value:'2'}],
	fields:['name','value']
});

var gridColumns=[expander,
//new Ext.grid.RowNumberer(),
{ dataIndex: "cliOrdMasterId", hidden:true, hideable:false
},{ dataIndex: "suppOrdMasterId", hidden:true, hideable:false
},{ dataIndex: "inlayDiaBatch", hidden:true, hideable:false
},{ dataIndex: "stateName", hidden:true, hideable:false
},{ dataIndex: "name", hidden:true, hideable:false
},{ dataIndex: "inlayBatch", hidden:true, hideable:false
},{ dataIndex: "inlayDiaBatch", hidden:true, hideable:false
},{ dataIndex: "type", hidden:true, hideable:false
},{ dataIndex: "material", hidden:true, hideable:false
},{ dataIndex: "hand", hidden:true, hideable:false
},{ dataIndex: "text", hidden:true, hideable:false
},{ dataIndex: "inlayFactoryBatch", hidden:true, hideable:false
},{ dataIndex: "cmpName", hidden:true, hideable:false
},{
    header: "钻石编号",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 80,
    dataIndex: "batch"
},{
    header: "下单时间",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 80,
    dataIndex: "orderDate"
},{
    header: "重量",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "weight"
},{
    header: "颜色",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "color"
},{
    header: "净度",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "clarity"
},{
    header: "抛光",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "polish"
},{
    header: "荧光",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "fluor"
},{
    header: "形状",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "shape"
},{
    header: "对称性",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "symmetry"
},{
    header: "切工",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 50,
    dataIndex: "finalCut"
},{
    header: "证书号",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 80,
    dataIndex: "reportNo"
},{
    header: "单价",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 60,
    dataIndex: "price"
},{
    header: "订单编号",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 120,
    dataIndex: "orderNo"
},{
    header: "客户名称",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 80,
    dataIndex: "userName"
},{
    header: "供应商名称",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 80,
    dataIndex: "supplierName"
},{
    header: "状态",
    align : 'center',
    sortable: true,
    resizable: true,
    width: 60,
    dataIndex: "stateName"
}]
function getFieldsFromColumns(colums){
	var fs=new Array();
	Ext.each(colums,function(col){
		fs.push(col.dataIndex);
	})
	return fs;
}
var gridModel=new Ext.grid.ColumnModel({
  defaultSortable: true,
  defaultWidth: 85,
  columns:gridColumns
})

var gridStore=new Ext.data.JsonStore({
	url:'queryClientOrderDetail.action',
	totalProperty: 'obj.totalSize', 
	successProperty :'success',
	root:'obj.returnBolist',
	messageProperty:'msg',
	fields:getFieldsFromColumns(gridColumns),
	listeners:{
		load:function(store,records){
			log.info('load event....')
			var proxyManagerRds=[];//钻托信息。不予以展示；
			var rds=new Ext.util.MixedCollection({});
			Ext.each(records,function(rd){
				log.info('select data....')
//				rd.data.type=store.reader.jsonData.obj.type;
				if(Ext.isEmpty(rd.data.inlayDiaBatch)){
					rds.add(rd.data.batch,rd);
				}else{
					log.info('find  proxyManagerRds....')
					proxyManagerRds.push(rd);
//					rds.add(rd.data.inlayDiaBatch,rd);
				}
			})
			Ext.each(proxyManagerRds,function(rd){
				log.info('remove record...')
				var m=rds.get(rd.data.inlayDiaBatch);
				m.set('proxy',rd.data);
				store.remove(rd);
			})
		}
	}
});

var orderDetailGrid = new Ext.grid.EditorGridPanel({
	store: gridStore,
	cm: gridModel,
	bbar : new Ext.PagingToolbar({
		pageSize : 15,
		store : gridStore,
		displayInfo:true,
		displyMsg : '显示第{0}条到第{1}条记录，一共{2}条',
		emptyMsg : "没有记录"
	}),
	plugins:[expander] ,
	frame: true
});

//grid1.on( {
//
//});


var queryOrderPanel=new Ext.FormPanel({
	layout:'column',
	id : 'queryOrderPanel',
	frame:true,
	regetion:'north',
	defaults:{
		layout:'form',
		labelWidth:55,
		defaults:{
			anchor: '85%'
		}
	},
	items:[{
		columnWidth:0.17,
		items:[{
			fieldLabel:'商品编号',
			id:'batch_fl',
			editable : false,
			triggerAction : 'all',
			displayField : 'name',
			valueField : 'value',
			name : 'batch',
			xtype:'textfield'
		}]
	},{
		columnWidth:0.3,
		xtype:'panel',
		layout:'column',
		defaults:{
			xtype:'panel',
			layout:'form',
			defaults:{
				xtype:'datefield',
				layout:'form',
				format : 'Y-m-d',
				anchor: '98%'
			}
		},
		items:[{
			columnWidth:0.55,
			items:[{
				fieldLabel:'成交时间',
				name : 'orderDateFrom',
				id : 'orderDateFrom'
			}]
		},{
			columnWidth:0.45,
			labelWidth:8,
			items:[{
				labelSeparator:'-',
				fieldLabel:'-',
				anchor: '85%',
				name : 'orderDateTo',
				id : 'orderDateTo'
			}]
		}]
	},{
		columnWidth:0.17,
		items:[{
			xtype:'combo',
	        fieldLabel: "客户名称",
			emptyText :'请选择客户',
			triggerAction : 'all',
	        displayField : 'userName',
	        valueField : 'userId',
			store:DealerStore,
			name:'userId',
			id:'userId_fl'
		}]
	},{
		columnWidth:0.17,
		items:[{
			xtype:'combo',
	        fieldLabel: "商品状态",
			emptyText :'请选择商品状态',
			mode:"local",
			triggerAction : 'all',
			value:'-1',
	        displayField : 'text',
			valueField : 'value',
			store:stateStore,
			name:'state',
			id:'state_fl'
		}]
	},{
		columnWidth:0.1,
		items:[{
			xtype:'button',
			text:'查询',
			id:'searchBt',
			anchor: '40%',
			handler:function(bt, e){
				queryOrderDetail();
			}
		}]
	}]
});

function queryOrderDetail() {
	var data=panel_gatherData(queryOrderPanel);
	var store=orderDetailGrid.getStore();
	store.baseParams ={json:Ext.encode(data)};
	store.reload();
}


Ext.onReady(function() {
	new Ext.Viewport({
		layout : 'border',
		items : [{
			region : 'north',
			split : true,
			border : false,
			height : 40,
			collapseMode : 'mini',
			layout : 'fit',
			items : [queryOrderPanel]
		}, {
			region : 'center',
			split : true,
			border : false,
			layout : 'fit',
			items : [orderDetailGrid]
		}]
	});
});
	
  